package com.huike.web.controller.clues;

import java.util.List;

import com.huike.clues.domain.vo.FalseClueVo;
import com.huike.clues.service.ITbClueService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;

/**
 * 线索跟进记录Controller
 * @date 2021-04-22
 */
@RestController
@RequestMapping("/clues/record")
public class TbClueTrackRecordController extends BaseController {

    @Autowired
    private ITbClueTrackRecordService clueTrackRecordService;

    /**
     * 跟进线索
     * @param clueId
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(Long clueId) {
        List<TbClueTrackRecord> list = clueTrackRecordService.selectTbClueTrackRecordList(clueId);
        return getDataTable(list);
    }

    /**
     * 新增线索跟进记录
     */
    @Log(title = "线索跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClueTrackRecordVo tbClueTrackRecord)
    {
        TbClueTrackRecord trackRecord=new TbClueTrackRecord();
        //将tbClueTrackRecord所有数据复制给trackRecord
        BeanUtils.copyProperties(tbClueTrackRecord,trackRecord);
        //设置trackRecord的创建时间
        trackRecord.setCreateTime(DateUtils.getNowDate());
        //设置trackRecord的创建人
        trackRecord.setCreateBy(SecurityUtils.getUsername());
        TbClue tbClue=new TbClue();
        //将trackRecord的所有数据复制给tbClue
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        //设置tbClue的状态和id
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue()); //进行中
        tbClue.setId(tbClueTrackRecord.getClueId());
        return toAjax(clueTrackRecordService.insertTbClueTrackRecord(tbClue,trackRecord));
    }



}